package com.example.qing.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.qing.config.AuthAccess;
import com.example.qing.config.LogType;
import com.example.qing.config.MyLogs;
import com.example.qing.pojo.Album;
import com.example.qing.pojo.Novel;
import com.example.qing.pojo.Result;
import com.example.qing.service.AlbumService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/album")
public class AlbumController {

    @Resource
    AlbumService albumService;

    @AuthAccess
    @GetMapping()
    public Result list() {
        List<Album> albumList = albumService.list();
        return Result.success(albumList);
    }
    @GetMapping("/total")
    public Result number(){
        long count=albumService.count();
        return Result.success(count);
    }
    @MyLogs(operation = "相册",type = LogType.DELETE)
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id){
        albumService.deleteAlbum(id);
        return Result.success();
    }
    @MyLogs(operation = "相册",type = LogType.UPDATE)
    @PutMapping("/update")
    public Result update(@RequestBody Album album){
        albumService.updateById(album);
        return Result.success();
    }
    @MyLogs(operation = "相册",type = LogType.ADD)
    @PostMapping("/add")
    public Result save(@RequestBody Album album){
        albumService.save(album);
        return Result.success();
    }

}
